/* global layui */

layui.use(['layer', 'form'], function () {
    var layer = layui.layer;
    var form = layui.form;
    var $ = layui.$;
    // 弹出框设置高度
    layer.config({offset: '50px'});
    // 表单提交
    form.on('submit(login)', function (data) {
        $.ajax({
            url: 'login',
            data: data.field,
            type: 'post',
            dataType: 'json',
            success: function (result) {
                if (0 === result.code) {
                    layer.msg(result.message, {time: 1000, icon: 1}, function () {
                        window.location.href = result.data.url;
                    });
                } else {
                    layer.msg(result.message, {time: 2000, icon: 5});
                }
            }
        });
        return false;
    });
});